package leetcode.twozerothree;

/**
 * Description: with recursion
 * Created By xxm
 */
public class Solution3 {
    public static ListNode removeElements(ListNode head, int val) {
        if (head == null) return null;

//        ListNode res = removeElements(head.next, val);
//        // head'val equal val
//        if (head.val == val) {
//            return res;
//        } else { // head'val not equal val
//            head.next = res;
//            return head;
//        }

        head.next = removeElements(head.next, val);
        return head.val == val ? head.next : head;
    }

    public static void main(String[] args) {
        int[] nums = {1, 2, 6, 3, 4, 5, 6};
        ListNode head = new ListNode(nums);

        System.out.println(head);

        System.out.println(removeElements(head, 6));
    }
}
